<template>
  <el-card class="empty">
    <MyVideoList v-if="count > 0" :list="videoList"></MyVideoList>
    <div v-else>
      <span>先上传个视频吧</span>
    </div>
    <div class="page-box">
      <el-pagination background layout="prev, pager, next" :current-page="page" :total="count" :page-size="page_size" :hide-on-single-page="shouPagination" @current-change="handleCurrent"></el-pagination>
    </div>
  </el-card>
</template>

<script>
import { getMineVideo } from "@/api/video";
import MyVideoList from "@/components/MyVideoList";
export default {
  data() {
    return {
      videoList: [],
      page: 0,
      page_size: 8,
      count: 0,
      shouPagination: true, //隐藏分页
    };
  },
  methods: {
    _getVideoList() {
      getMineVideo(this.page, this.page_size).then((res) => {
        if (res.data.code === 200) {
          if (this.count == 0) {
            //只有查询第一页才返回总数
            this.count = res.data.data.count;
            if (this.count > this.page_size) {
              this.shouPagination = false;
            }
          }
          this.videoList = res.data.data.data;
        }        
      }).catch((err) => {
        this.$message.error(err.response.data.msg);
      });
    },
    handleCurrent(page) {
      this.page = page;
      this._getVideoList();
    },
  },
  created() {
    this.page = 1;
    this._getVideoList();
  },
  components: {
    MyVideoList,
  },
};
</script>
<style >
.empty {
  min-height: 500px;
}

.page-box{
  text-align:center;
}
</style>